package com.planet.common.autoconfigure.sms;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * @Description: TODO 星球短信自动配置
 * @Author: mis_wu
 * @Date: 2023/8/27
 * @Company SMS
 **/
@Configuration(proxyBeanMethods = false)
@ConditionalOnWebApplication
@EnableConfigurationProperties(PlanetSmsProperties.class)
@ConditionalOnProperty(prefix = "spring.planet.sms",name = "enable",havingValue = "true")
public class PlanetSmsAutoconfiguration {

    @Resource
    private PlanetSmsProperties planetSmsProperties;

    @Bean(name = "planetSmsProducer")
    @ConditionalOnMissingBean
    public PlanetSmsSender smsProducer(){
        PlanetSmsSender smsSender = new PlanetSmsSender();
        smsSender.setPlanetSmsProperties(planetSmsProperties);
        return smsSender;
    }
}
